<?php
 include "counter2.php";
 $placeid = $counter->get_input('placeid', '', 'get');
 $email = $counter->get_input('email', '', 'get');

pagestart(); ?>
<html>
<?php pagehead(_("Lost emails")) ?>
<body bgcolor="white">
<?php pagetop(_("Lost emails")) ?>
<?php print _("The list of people below do not have any valid email address by which they can be contacted any more.") ?>
<p>
<?php
  if ($placeid) {
     $cleared_placeid = mysql_escape_string($placeid);
     $placeidpart = "and persons.placeid like '$cleared_placeid%'";
     print _("This is the first 100 of the") . " ";
     print _("entries within ") . "\"$placeid\"";
  } else if ($email) {
     $cleared_email = mysql_escape_string($email);
     print _("TEST email");
     $placeidpart = "and email.f_key like '$cleared_email%'";
  } else {
     print _("This is the first 100 of the ");
     echo dbcount('email', "email.usage = 'main' and email.state = 'bad'");
     print _(" entries");
     $placeidpart = "";
  }
?>
 <?php print _("with known bad reply-to.") ?>
<p>
<?php print _("To limit to a specific geographical area,  type its ID here.") ?>
<form action="<?php echo $SCRIPT_NAME?>">
<?php print _("ID") . ":" ?> <input name="placeid" value="<?php echo $placeid?>"><br>
<?php print _("Email:") ?> <input name="email" value="<?php echo $email?>"><br>
<?php print "<input type=submit value=\"" . _("Go") . "!" . "\">" ?>
</form>
<table class="info" border>
<tr><th><?php print _("Key") ?><th><?php print _("Email") ?><th><?php print _("Name") ?><th><?php print _("Error") ?>
<?php
  $query = mysql_query("select persons.f_key, email.f_key, persons.name, email.error from persons, email where persons.f_key = email.owner and email.state = 'bad' and email.usage = 'main' $placeidpart order by email.f_key limit 100");

  while ($arr = mysql_fetch_row($query)) {
	$arr[0] = htmlspecialchars($arr[0]);
	echo "<tr><td>";
	echo "<a href=\"/cgi-bin/adm/display-person.cgi?user=$arr[0]\">$arr[0]</a>";
	echo "<td>" . htmlspecialchars($arr[1]);
	echo "<td>" . htmlspecialchars($arr[2]);
	echo "<td>" . htmlspecialchars($arr[3]);
	echo "<td>" . htmlspecialchars($arr[4]);
 }
?>
</table>
<?php pagebottom() ?>
</body>
</html>
